package by.gravity.grsu.shedule.api;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class GrsuSheduleAPI implements SheduleConstants {

	public static final String getSpeciality() {
		return getBaseUrl() + "Speciality";
	}

	public static final String getKurs(String speciality) {
		return getUrl("Kurs?spec=%1$s", speciality);
	}

	public static final String getGroups(String specialtiy, String kurs) {
		return getUrl("Group?spec=%1$s&kurs=%2$s", specialtiy, kurs);
	}

	public static final String getWeekShedule(String speciality, String kurs, String group, long weeDateStart) {
		return getUrl("Week?spec=%1$s&kurs=%2$s&group=%3$s&date=%4$s", speciality, kurs, group,
				String.valueOf(weeDateStart));
	}

	private static final String getBaseUrl() {
		return BASE_URL + SERVICE_NAME;
	}

	private static final String getUrl(String query, String... queryParams) {
		for (int i = 0; i < queryParams.length; i++) {
			try {
				queryParams[i] = URLEncoder.encode(queryParams[i], "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return String.format((getBaseUrl() + query), queryParams);

	}
}
